<%-- 
    Document   : busca
    Created on : 16/09/2014, 15:23:01
    Author     : luiz
--%>

<%@page import="java.io.OutputStreamWriter"%>
<%@page import="java.net.HttpURLConnection"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="java.io.InputStreamReader"%>
<%@page import="java.io.BufferedReader"%>
<%@page import="java.net.URLConnection"%>
<%@page import="java.net.URL"%>
<%@page import="java.util.Set"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<script type="text/javascript" src="ajax.js"></script>
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859">
    </head>
    <body>
        <h1> 
        </h1>

        <%
            String cep = request.getParameter("cep");
            URL url = new URL("http://localhost:8080/ajax_1/DatabaseAccess?cep=" + cep);
            HttpURLConnection conection = (HttpURLConnection) url.openConnection();
            conection.setRequestProperty("Request-Method", "GET");
            conection.setDoInput(true);
            conection.setDoOutput(true);
            conection.connect();
            BufferedReader br = new BufferedReader(new InputStreamReader(conection.getInputStream()));
            StringBuffer dadosSite = new StringBuffer(10000);
            String saida = "";
            while (null != ((saida = br.readLine()))) {
                dadosSite.append(saida);
            }
            System.out.print(dadosSite.toString());
            br.close();
            
            String[] dados = dadosSite.toString().split(";");
        %>


        <label for="endereco">Endereço</label>
        <input id="endereco" name="endereco" size="30" type="text" value="<%=dados[1]%>"/>
        <br/>
        <label for="numero">Numero</label>
        <input id="numero" name="numero" size="30" type="text" autofocus/>
        <br/>
        <label for="bairro">Bairro</label>
        <input id="bairro" name="bairro" size="30" type="text" value="<%=dados[2]%>"/>
        <br/>
        <label for="complemento">Complemento</label>
        <input id="complemento" name="complemento" size="30" type="text" value="<%=dados[0]%>" />
        <br/>
        <label for="estado">Estado:</label>
        <input id="estado" name="estado" size="30" type="text" disable value="<%=dados[4]%>"/>
        <br/>
        <label for="cidade">Cidade:</label> 
        <input id="cidade" name="cidade" size="30" type="text" disable value="<%=dados[3]%>"/>
    </body>
</html>
